home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCCP024.ARJ / TERM.C < prev    next >
Text File  |  1992-05-17  |  16KB  |  783 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  */
  3.  
  4. #include<stdio.h>
  5. #include<bios.h>
  6. #include<dos.h>
  7. #include<fcntl.h>
  8. #include<graph.h>
  9. #include"emu.h"
  10. #include"color.h"
  11. #include"port.h"
  12.  
  13.  
  14. dispkbd(code)
  15.     unsigned short code;
  16.     {
  17.     int i;
  18.     long tstamp, tstamp1, dayofticksp;
  19.     unsigned char ccode, scode;
  20.     ccode=code&0xff;
  21.     scode=(code>>8)&0xff;
  22.     if(ccode)
  23.         {
  24.         while(!(inp(basereg+STATREG)&0x20));
  25.         outp(basereg, code);
  26.         }
  27.     else
  28.         if(!emu.keys[scode].len)
  29.             putch(0x07);
  30.         else
  31.             for(i=0;i<emu.keys[scode].len;i++)
  32.                 {
  33.                 while(!(inp(basereg+STATREG)&0x20));
  34.                 if(emu.keys[scode].nullpause_p&&!emu.keys[scode].chars[i])
  35.                     {
  36.                     _bios_timeofday(_TIME_GETCLOCK, &tstamp);
  37.                     dayofticksp=0;
  38.                     while(1)
  39.                         {
  40.                         if(_bios_timeofday(_TIME_GETCLOCK, &tstamp1))
  41.                             dayofticksp+=20*60*60*24;
  42.                         if(tstamp1+dayofticksp-tstamp>22)
  43.                             break;
  44.                         }
  45.                     }
  46.                 else if(emu.keys[scode].nullpause_p&&(emu.keys[scode].chars[i]==0xff))
  47.                     {
  48.                     _bios_timeofday(_TIME_GETCLOCK, &tstamp);
  49.                     outp(basereg+LCTLREG, lctl|0x40);
  50.                     dayofticksp=0;
  51.                     while(1)
  52.                         {
  53.                         if(_bios_timeofday(_TIME_GETCLOCK, &tstamp1))
  54.                             dayofticksp+=20*60*60*24;
  55.                         if(tstamp1+dayofticksp-tstamp>10)
  56.                             break;
  57.                         }
  58.                     outp(basereg+LCTLREG, lctl);
  59.                     }
  60.                 else
  61.                     outp(basereg, emu.keys[scode].chars[i]);
  62.                 }
  63.     }
  64.  
  65. #define LISTSIZ 16
  66.  
  67. struct
  68.     {
  69.     short index;
  70.     short row;
  71.     short column;
  72.     short list[LISTSIZ];
  73.     short listindex;
  74.     }
  75.     funcstor[NFUNCS];
  76.  
  77. clrfuncstor(seqn)
  78.     short seqn;
  79.     {
  80.     int i;
  81.     for(i=funcstor[seqn].listindex-1;i>=0;i--)
  82.         funcstor[seqn].list[i]=0;
  83.     funcstor[seqn].row=funcstor[seqn].column=funcstor[seqn].listindex=funcstor[seqn].index=0;
  84.     }
  85.  
  86. int bold, faint, blink, inverse, bkcolor, fgcolor;
  87. struct videoconfig far *vconf;
  88.  
  89. atthndl()
  90.     {
  91.     int adds, workingbk, workingfg;
  92.     adds=0;
  93.     if(vconf->adapter!=_MDPA)
  94.         {
  95.         workingbk=bkcolor;
  96.         workingfg=fgcolor;
  97.         if(faint)
  98.             if(inverse)
  99.                 if(bkcolor==WHITE)
  100.                     workingbk=GRAY;
  101.                 else
  102.                     adds+=FAINTADD;
  103.             else
  104.                 if(fgcolor==WHITE)
  105.                     workingfg=GRAY;
  106.                 else
  107.                     adds+=FAINTADD;
  108.         else
  109.             if(bold)
  110.                 {
  111.                 if(bkcolor==WHITE)
  112.                     workingbk=BWHITE;
  113.                 if(fgcolor==WHITE)
  114.                     workingfg=BWHITE;
  115.                 }
  116.         if(blink)
  117.             adds+=BLINKADD;
  118.         if(inverse)
  119.             {
  120.             if(blink)
  121.                 _settextcolor(workingbk+BLINKADD);
  122.             else
  123.                 _settextcolor(workingbk);
  124.             if(faint)
  125.                 _setbkcolor((long)(workingfg+FAINTADD));
  126.             else
  127.                 _setbkcolor((long)workingfg);
  128.             }
  129.         else
  130.             {
  131.             _settextcolor(workingfg+adds);
  132.             _setbkcolor((long)workingbk);
  133.             }
  134.         }
  135.     else
  136.         {
  137.         workingbk=BLACK;
  138.         if(bold&&!inverse)
  139.             workingfg=M_UNDER;
  140.         else
  141.             if(inverse)
  142.                 workingfg=WHITE;
  143.             else
  144.                 workingfg=M_NORMAL;
  145.         if(faint)
  146.             adds+=FAINTADD;
  147.         if(blink)
  148.             adds+=BLINKADD;
  149.         if(inverse)
  150.             {
  151.             if(blink)
  152.                 _settextcolor(workingbk+BLINKADD);
  153.             else
  154.                 _settextcolor(workingbk);
  155.             _setbkcolor((long)workingfg);
  156.             }
  157.         else
  158.             {
  159.             _settextcolor(workingfg+adds);
  160.             _setbkcolor((long)workingbk);
  161.             }
  162.         }
  163.     }
  164.  
  165.  
  166. ansiatthndl(seqn)
  167.     short seqn;
  168.     {
  169.     int i, adds, workingbk, workingfg;
  170.     if(emu.funcs[seqn].func==ANSIATTRIB)
  171.         for(i=0;i<funcstor[seqn].listindex;i++)
  172.             switch(funcstor[seqn].list[i])
  173.                 {
  174.                 /*at the moment this is strictly ANSI subset*/
  175.                 case 0:
  176.                     bkcolor=BLACK;
  177.                     fgcolor=WHITE;
  178.                     bold=faint=blink=inverse=0;
  179.                     break;
  180.                 case 1:
  181.                     bold=1;
  182.                     break;
  183.                 case 2:
  184.                     faint=1;
  185.                     break;
  186.                 case 5:
  187.                 case 6:
  188.                     blink=1;
  189.                     break;
  190.                 case 7:
  191.                     inverse=1;
  192.                     break;
  193.                 case 8:
  194.                 case 30:
  195.                 case 40:
  196.                     fgcolor=bkcolor;
  197.                     break;
  198.                 case 31:
  199.                 case 41:
  200.                     fgcolor=RED;
  201.                     break;
  202.                 case 32:
  203.                 case 42:
  204.                     fgcolor=GREEN;
  205.                     break;    
  206.                 case 33:
  207.                 case 43:
  208.                     fgcolor=YELLOW;
  209.                     break;
  210.                 case 34:
  211.                 case 44:
  212.                     fgcolor=BLUE;
  213.                     break;
  214.                 case 35:
  215.                 case 45:
  216.                     fgcolor=MAGENTA;
  217.                     break;
  218.                 case 36:
  219.                 case 46:
  220.                     fgcolor=CYAN;
  221.                     break;
  222.                 case 37:
  223.                 case 47:
  224.                     fgcolor=WHITE;
  225.                     break;
  226.                 default:
  227.                     break;
  228.                 }
  229.     atthndl();
  230.     }
  231.  
  232. int wrap_p;
  233.  
  234. wrapctl()
  235.     {
  236.     if(wrap_p)
  237.         _wrapon(_GWRAPON);
  238.     else
  239.         _wrapon(_GWRAPOFF);
  240.     }
  241.  
  242. char fpname[256], dribpname[256];
  243.  
  244. updstatus()
  245.     {
  246.     struct rccoord posptr;
  247.     short tc;
  248.     long bc;
  249.     char str[80];
  250.     posptr=_gettextposition();
  251.     tc=_gettextcolor();
  252.     bc=_getbkcolor();
  253.     _settextwindow(1,1,1,80);
  254.     _settextposition(1,1);
  255.     _settextcolor(BLACK);
  256.     _setbkcolor((long)WHITE);
  257.     _wrapon(_GWRAPOFF);
  258.     sprintf(str, "Both Shifts to Exit COM%u %5u %c%c%c %22s %22s",
  259.         comnum+1, speed, databits, parity, stopbits, fpname, dribpname);
  260.     _outtext(str);
  261.     _settextwindow(2,1,25,80);
  262.     wrapctl();
  263.     _settextcolor(tc);
  264.     _setbkcolor(bc);
  265.     _settextposition(posptr.row, posptr.col);
  266.     }
  267.  
  268. int graphics;
  269.  
  270. showchar(c)
  271.     char c;
  272.     {
  273.     char str[2];
  274.     if(graphics)
  275.         if(emu.gchars[c])
  276.             c=emu.gchars[c];
  277.     str[0]=c;
  278.     str[1]='\0';
  279.     _outtext(str);
  280.     }
  281.  
  282. perffunc(seqn)
  283.     short seqn;
  284.     {
  285.     struct rccoord posptr;
  286.     int i;
  287.     switch(emu.funcs[seqn].func)
  288.         {
  289.         case CLEAR:
  290.             _clearscreen(_GCLEARSCREEN);
  291.             updstatus();
  292.             _settextposition(1,1);
  293.             break;
  294.         case HOME:
  295.             _settextposition(1,1);
  296.             break;
  297.         case CLREOL:
  298.             posptr=_gettextposition();
  299.             _wrapon(_GWRAPOFF);
  300.             for(i=posptr.col;i<=80;i++)
  301.                 _outtext(" ");
  302.             _settextposition(posptr.row, posptr.col);
  303.             wrapctl();
  304.             break;
  305.         case UP:
  306.             posptr=_gettextposition();
  307.             if(posptr.row>1)
  308.                 _settextposition(posptr.row-1, posptr.col);
  309.             break;
  310.         case DOWN:
  311.             posptr=_gettextposition();
  312.             if(posptr.row<24)
  313.                 _settextposition(posptr.row+1, posptr.col);
  314.             else
  315.                 {
  316.                 showchar('\n');
  317.                 _settextposition(posptr.row, posptr.col);
  318.                 }
  319.             break;
  320.         case LEFT:
  321.             posptr=_gettextposition();
  322.             if(posptr.col>1)
  323.                 _settextposition(posptr.row, posptr.col-1);
  324.             break;
  325.         case RIGHT:
  326.             posptr=_gettextposition();
  327.             if(posptr.col<80)
  328.                 _settextposition(posptr.row, posptr.col+1);
  329.             break;
  330.         case GOTO:
  331.             if(funcstor[seqn].row<1)
  332.                 funcstor[seqn].row=1;
  333.             if(funcstor[seqn].row>24)
  334.                 funcstor[seqn].row=24;
  335.             if(funcstor[seqn].column<1)
  336.                 funcstor[seqn].column=1;
  337.             if(funcstor[seqn].column>80)
  338.                 funcstor[seqn].row=80;
  339.             _settextposition((emu.tophi_p?25-funcstor[seqn].row:funcstor[seqn].row), funcstor[seqn].column);
  340.             break;
  341.         case NORMAL:
  342.             fgcolor=WHITE;
  343.             bkcolor=BLACK;
  344.             blink=faint=bold=inverse=0;
  345.             atthndl();
  346.             break;
  347.         case BLINK:
  348.             blink=1;
  349.             atthndl();
  350.             break;
  351.         case NOBLINK:
  352.             blink=0;
  353.             atthndl();
  354.             break;
  355.         case BOLD:
  356.             bold=1;
  357.             atthndl();
  358.             break;
  359.         case NOBOLD:
  360.             bold=0;
  361.             atthndl();
  362.             break;
  363.         case FAINT:
  364.             faint=1;
  365.             atthndl();
  366.             break;
  367.         case NOFAINT:
  368.             faint=0;
  369.             atthndl();
  370.             break;
  371.         case INVERSE:
  372.             inverse=1;
  373.             atthndl();
  374.             break;
  375.         case NOINVERSE:
  376.             inverse=0;
  377.             atthndl();
  378.             break;
  379.         case UPN:
  380.             posptr=_gettextposition();
  381.             if(posptr.row-funcstor[seqn].row<1)
  382.                 _settextposition(1, posptr.col);
  383.             else
  384.                 _settextposition(posptr.row-funcstor[seqn].row, posptr.col);
  385.             break;
  386.         case DOWNN:
  387.             posptr=_gettextposition();
  388.             if(posptr.row+funcstor[seqn].row>24)
  389.                 {
  390.                 _settextposition(24,1);
  391.                 for(i=25-(posptr.row+funcstor[seqn].row);i<0;++i)
  392.                     showchar('\n');
  393.                 _settextposition(24, posptr.col);
  394.                 }
  395.             else
  396.                 _settextposition(posptr.row+funcstor[seqn].row, posptr.col);
  397.             break;
  398.         case LEFTN:
  399.             posptr=_gettextposition();
  400.             if(posptr.col-funcstor[seqn].column<1)
  401.                 _settextposition(posptr.row, 1);
  402.             else
  403.                 _settextposition(posptr.row, posptr.col-funcstor[seqn].column);
  404.             break;
  405.         case RIGHTN:
  406.             posptr=_gettextposition();
  407.             if(posptr.col+funcstor[seqn].column>80)
  408.                 _settextposition(posptr.row, 80);
  409.             else
  410.                 _settextposition(posptr.row, posptr.col+funcstor[seqn].column);
  411.             break;
  412.         case ANSIATTRIB:
  413.             ansiatthndl(seqn);
  414.             break;
  415.         case WRAP:
  416.             wrap_p=1;
  417.             wrapctl();
  418.             break;
  419.         case NOWRAP:
  420.             wrap_p=0;
  421.             wrapctl();
  422.             break;
  423.         case GOTOLINE:
  424.             posptr=_gettextposition();
  425.             if(funcstor[seqn].row<1)
  426.                 funcstor[seqn].row=1;
  427.             if(funcstor[seqn].row>24)
  428.                 funcstor[seqn].row=24;
  429.             _settextposition(emu.tophi_p?25-funcstor[seqn].row:funcstor[seqn].row, posptr.col);
  430.             break;
  431.         case GOTOCOL:
  432.             posptr=_gettextposition();
  433.             if(funcstor[seqn].column<1)
  434.                 funcstor[seqn].column=1;
  435.             if(funcstor[seqn].column>80)
  436.                 funcstor[seqn].row=80;
  437.             _settextposition(posptr.row, funcstor[seqn].column);
  438.             break;
  439.         case WYSEATTR:
  440.             if(funcstor[seqn].row&0x02)
  441.                 blink=1;
  442.             else
  443.                 blink=0;
  444.             if(funcstor[seqn].row&0x04)
  445.                 inverse=1;
  446.             else
  447.                 inverse=0;
  448.             if(funcstor[seqn].row&0x08)
  449.                 bold=1;
  450.             else
  451.                 bold=0;
  452.             if(funcstor[seqn].row&0x40)
  453.                 faint=1;
  454.             else
  455.                 faint=0;
  456.             atthndl();
  457.             break;
  458.         case GRAPHCHAR:
  459.             showchar(emu.gchars[funcstor[seqn].row]);
  460.             break;
  461.         case BEGGRAPH:
  462.             graphics=1;
  463.             break;
  464.         case ENDGRAPH:
  465.             graphics=0;
  466.             break;
  467.         case TAB:
  468.             posptr=_gettextposition();
  469.             _settextposition(posptr.row, posptr.col+(8-((posptr.col-1)%8)));
  470.             break;
  471.         case BELL:
  472.             putch(7);
  473.             break;
  474.         case DTAB:
  475.             posptr=_gettextposition();
  476.             for(i=0;i<(8-((posptr.col-1)%8));++i)
  477.                 _outtext(" ");
  478.  
  479.         default:
  480.             break;
  481.         }
  482.     }
  483.  
  484. dispport(c)
  485.     unsigned char c;
  486.     {
  487.     int seqn, done, ok;
  488.     done=0;
  489.     ok=0;
  490.     for(seqn=0;seqn<NFUNCS;seqn++)
  491.         {
  492.         if(emu.funcs[seqn].codes[funcstor[seqn].index]&0xff00)
  493.             switch(emu.funcs[seqn].codes[funcstor[seqn].index])
  494.                 {
  495.                 case END:
  496.                     if(funcstor[seqn].index)
  497.                         {
  498.                         done=1;
  499.                         perffunc(seqn);
  500.                         }
  501.                     break;
  502.                 case BINCOL:
  503.                     funcstor[seqn].column=c-emu.bincoloff;
  504.                     ok=1;
  505.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  506.                         {
  507.                         done=1;
  508.                         perffunc(seqn);
  509.                         }
  510.                     break;
  511.                 case BINROW:
  512.                     funcstor[seqn].row=c-emu.binrowoff;
  513.                     ok=1;
  514.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  515.                         {
  516.                         done=1;
  517.                         perffunc(seqn);
  518.                         }
  519.                     break;
  520.                 case ASCDECCOL:
  521.                     if((c>='0')&&(c<='9'))
  522.                         {
  523.                         ok=1;
  524.                         funcstor[seqn].column*=10;
  525.                         funcstor[seqn].column+=(c-'0');
  526.                         }
  527.                     else
  528.                         if(c==emu.funcs[seqn].codes[++funcstor[seqn].index])
  529.                             {
  530.                             ok=1;
  531.                             if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  532.                                 {
  533.                                 done=1;
  534.                                 perffunc(seqn);
  535.                                 }
  536.                             }
  537.                         else
  538.                             clrfuncstor(seqn);
  539.                     break;
  540.                 case ASCDECROW:
  541.                     if((c>='0')&&(c<='9'))
  542.                         {
  543.                         ok=1;
  544.                         funcstor[seqn].row*=10;
  545.                         funcstor[seqn].row+=(c-'0');
  546.                         }
  547.                     else
  548.                         if(c==emu.funcs[seqn].codes[++funcstor[seqn].index])
  549.                             {
  550.                             ok=1;
  551.                             if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  552.                                 {
  553.                                 done=1;
  554.                                 perffunc(seqn);
  555.                                 }
  556.                             }
  557.                         else
  558.                             clrfuncstor(seqn);
  559.                     break;
  560.                 case ASCDECSEMILIST:
  561.                     if((c>='0')&&(c<='9'))
  562.                         {
  563.                         ok=1;
  564.                         funcstor[seqn].list[funcstor[seqn].listindex]*=10;
  565.                         funcstor[seqn].list[funcstor[seqn].listindex]+=(c-'0');
  566.                         }
  567.                     else
  568.                         {
  569.                         if(funcstor[seqn].listindex<LISTSIZ)
  570.                             funcstor[seqn].listindex++;
  571.                         
  572.                         if(c==';')
  573.                             ok=1;
  574.                         else
  575.                             if(c==emu.funcs[seqn].codes[++funcstor[seqn].index])
  576.                                 {
  577.                                 ok=1;
  578.                                 if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  579.                                     {
  580.                                     done=1;
  581.                                     perffunc(seqn);
  582.                                     }
  583.                                 }
  584.                             else
  585.                                 clrfuncstor(seqn);
  586.                         }
  587.                     break;
  588.                 case GRABCHAR:
  589.                     ok=1;
  590.                     funcstor[seqn].row=c;
  591.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  592.                         {
  593.                         done=1;
  594.                         perffunc(seqn);
  595.                         }
  596.                     break;
  597.                 case GRAPHCHAR_T:
  598.                     if(emu.gchars[c])
  599.                         {
  600.                         ok=1;
  601.                         funcstor[seqn].row=c;
  602.                         if(emu.funcs[seqn].codes[funcstor[seqn].index]==END)
  603.                             {
  604.                             done=1;
  605.                             perffunc(seqn);
  606.                             }
  607.                         }
  608.                     else
  609.                         clrfuncstor(seqn);
  610.                     break;
  611.                 }
  612.         else
  613.             if(c==emu.funcs[seqn].codes[funcstor[seqn].index])
  614.                 {
  615.                 ok=1;
  616.                 if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  617.                     {
  618.                     done=1;
  619.                     perffunc(seqn);
  620.                     }
  621.                 }
  622.             else
  623.                 clrfuncstor(seqn);
  624.         if(done)
  625.             {
  626.             ok=1;
  627.             for(seqn=0;seqn<NFUNCS;seqn++)
  628.                 clrfuncstor(seqn);
  629.             break;
  630.             }
  631.         }
  632.     if(!ok)
  633.         showchar(c);
  634.     }
  635.  
  636. initdisp()
  637.     {
  638.     int i;
  639.     for(i=0;i<NFUNCS;i++)
  640.         {
  641.         funcstor[i].listindex=LISTSIZ;
  642.         clrfuncstor(i);
  643.         }
  644.     bold=faint=blink=inverse=0;
  645.     fgcolor=WHITE;
  646.     bkcolor=BLACK;
  647.     graphics=0;
  648.     wrap_p=emu.default_wrap_p;
  649.     }
  650.  
  651. main(argc, argv)
  652.     int argc;
  653.     char **argv;
  654.     {
  655.     FILE *dribble;
  656.     char c;
  657.     int follow, emufd, i, orun;
  658.     if(!strcmp(getenv("REMOTE"), "YES"))
  659.         {
  660.         printf("You appear to be logged in remotely, judging by the environment\n");
  661.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  662.         printf("Are you sure you want to run TERM? (y or n) --> ");
  663.         if(getchar()!='y') /* Note getchar() and not getch()! */
  664.             {
  665.             printf("I didn't think so!\n");
  666.             exit(99);
  667.             }
  668.         else
  669.             printf("OK, you're the boss!\n");
  670.         }
  671.     _getvideoconfig(vconf);
  672.     index=follow=0;
  673.     if((argc<4)||(argc>6))
  674.         {
  675.         printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  676.         printf("USAGE: term <comnum> <bps> <data><parity><stop> [<emu or - >] [<dribble>]\n");
  677.         printf("<emu> is an emulation file base pathname.\n");
  678.         printf("<dribble> is a dribble (text capture) file.\n");
  679.         printf("The environment variable PCCPPATH is used for the emulation file if set.\n");
  680.         exit(1);
  681.         }
  682.     fpname[0]='\0';
  683.     dribpname[0]='\0';
  684.     if((argc>=5)&&(argv[4][0]!='-'))
  685.         {
  686.         if((getenv("PCCPPATH")==NULL)||(argv[4][0]=='\\')||(argv[4][1]==':'))
  687.             sprintf(fpname, "%s.emu", argv[4]);
  688.         else
  689.             sprintf(fpname, "%s\\%s.emu", getenv("PCCPPATH"), argv[4]);
  690.         if((emufd=open(fpname, O_RDONLY|O_BINARY))==-1)
  691.             {
  692.             printf("Error opening emulation file %s.\n", fpname);
  693.             exit(2);
  694.             }
  695.         else
  696.             if(read(emufd, &emu, sizeof(emu))!=sizeof(emu))
  697.                 {
  698.                 printf("Error reading emulation file %s.\n", fpname);
  699.                 exit(3);
  700.                 }
  701.             else;
  702.         }
  703.     else
  704.         {
  705.         nullemu();
  706.         emu.funcs[0].func=LEFT;
  707.         emu.funcs[0].codes[0]='\b';
  708.         emu.funcs[0].codes[1]=END;
  709.         emu.funcs[1].func=DTAB;
  710.         emu.funcs[1].codes[0]='\t';
  711.         emu.funcs[1].codes[1]=END;
  712.         emu.funcs[2].func=BELL;
  713.         emu.funcs[2].codes[0]='\007';
  714.         emu.funcs[2].codes[1]=END;
  715.         }
  716.     if(argc==6)
  717.         {
  718.         strcpy(dribpname, argv[5]);
  719.         if((dribble=fopen(argv[5], "a"))==NULL)
  720.             {
  721.             printf("Couldn't open dribble file %s.\n");
  722.             exit(10);
  723.             }
  724.         else
  725.             fprintf(dribble, "\nBeginning of dribble segment.\n\n");
  726.         }
  727.     else
  728.         dribble=NULL;
  729.     comnum=atoi(argv[1])-1;
  730.     speed=atoi(argv[2]);
  731.     parity=argv[3][1];
  732.     databits=argv[3][0];
  733.     stopbits=argv[3][2];
  734.     setport();
  735.     readset();
  736.     setup();
  737.     _clearscreen(_GCLEARSCREEN);
  738.     initdisp();
  739.     updstatus();
  740.     atthndl();
  741.     _settextposition(1,1);
  742.     orun=0;
  743.     while(1)
  744.         {
  745.         if((_bios_keybrd(_KEYBRD_SHIFTSTATUS) & 3) == 3)
  746.             {
  747.             cleanup();
  748.             _settextcolor(WHITE);
  749.             _setbkcolor((long)BLACK);
  750.             if(dribble!=NULL)
  751.                 {
  752.                 fprintf(dribble, "\nEnd of dribble segment.\n");
  753.                 fclose(dribble);
  754.                 }
  755.             _outtext("\nOrderly exit from TERM.\n");
  756.             exit(0);
  757.             }
  758.         if(_bios_keybrd(_KEYBRD_READY))
  759.             dispkbd(_bios_keybrd(_KEYBRD_READ));
  760.         if(follow!=index)
  761.             {
  762.             if(dribble!=NULL)
  763.                 fputc(buf[follow], dribble);
  764.             /* We only display if we're not too far behind; */
  765.             /* this makes dribble more reliable. */
  766.             if(((index-follow)>4096)||(((index-follow)<0)&&((follow-index)<4096)))
  767.                 if(!orun)
  768.                     {
  769.                     orun=1;
  770.                     initdisp();
  771.                     }
  772.                 else;
  773.             else
  774.                 {
  775.                 orun=0;
  776.                 dispport(buf[follow]);
  777.                 }
  778.             follow++;
  779.             follow=follow%TBUFSIZ;
  780.             }
  781.         }
  782.     }
  783.